/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.epfc.dnet.mastermind.model.utils;

import eu.epfc.dnet.mastermind.model.pojos.GameDataModel;
import eu.epfc.dnet.mastermind.model.pojos.Line;
import eu.epfc.dnet.mastermind.services.GameManager;
import java.util.List;

/**
 *
 * @author Pierre Buvé
 */
public class GameDataModelLoader {
    
    GameManager gameManager = new GameManager();
    PropositionCorrector propositionCorrector = new PropositionCorrector();
    
    /**
     * Methode chargée de peupler le gamedatamodel selon les informations stockées en db.
     * @param gameDataModel 
     */
    public void populateDataModel(GameDataModel gameDataModel) {
        int totalLineToLoad = gameDataModel.getCurrentLine() - 1;
        int gameId = gameDataModel.getGameId();
        Line tmpLine = new Line();
        
        // va chercher dans la db une liste des lines selon le gameId
        List<Line> lineList = gameManager.getAllLinesForGameId(gameId);
        
        if (totalLineToLoad > 0) {
            tmpLine = lineList.get(0);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine01(tmpLine);
        }
        if (totalLineToLoad > 1) {
            tmpLine = lineList.get(1);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine02(tmpLine);
        }
        if (totalLineToLoad > 2) {
            tmpLine = lineList.get(2);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine03(tmpLine);
        }
        if (totalLineToLoad > 3) {
            tmpLine = lineList.get(3);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine04(tmpLine);
        }
        if (totalLineToLoad > 4) {
            tmpLine = lineList.get(4);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine05(tmpLine);
        }
        if (totalLineToLoad > 5) {
            tmpLine = lineList.get(5);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine06(tmpLine);
        }
        if (totalLineToLoad > 6) {
            tmpLine = lineList.get(6);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine07(tmpLine);
        }
        if (totalLineToLoad > 7) {
            tmpLine = lineList.get(7);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine08(tmpLine);
        }
        if (totalLineToLoad > 8) {
            tmpLine = lineList.get(8);
            propositionCorrector.correctLine(tmpLine,gameDataModel.getSolution());
            gameDataModel.setLine09(tmpLine);
        }
    }
    
}
